<html xmlns="http://www.w3.org/1999/xhtml">
<head>
  <meta charset="utf-8">
  <title><!--{$lang.page.index.title}--></title>
  <meta name="renderer" content="webkit">
  <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
  <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
  <link rel="stylesheet" href="/static/lay/layui/css/layui.css" media="all">
  <link rel="stylesheet" href="/static/lay/layui/index.css" media="all">
</head>
<body>

<div class="layui-fluid">
    <div class="layui-card">
      <div class="layui-card-body" style="padding: 15px;">
        <div class="layui-form-item" style="text-align: center; height: 50px;"><b><!--{$lang.page.mue.ratemg}--></b></div>
        <form name="addItem" method="post" lay-filter="component-form-group" class="layui-form">
          <input type="hidden" value="<!--{$datainfo.id}-->" name="id">
          <input type="hidden" value="<!--{$authtype.authtype}-->" name="authtype">

          <div class="layui-form-item">

            <div class="layui-inline">
              <label class="layui-form-label"><!--{$lang.page.table.name}--></label>
              <div class="layui-input-inline">
               <input type="text" name="name" value="<!--{$datainfo.name}-->" lay-verify="name" placeholder="<!--{$lang.page.public.pinput}-->" autocomplete="off" class="layui-input" />
              </div>
            </div>

            <div class="layui-inline">
             <label class="layui-form-label"><!--{$lang.page.table.rate}--></label>
              <div class="layui-input-inline">
                <input type="text" name="rate" value="<!--{$datainfo.rate}-->" lay-verify="rate" placeholder="<!--{$lang.page.public.pinput}-->" autocomplete="off" class="layui-input" />
              </div>
            </div>

            <div class="layui-inline">
             <label class="layui-form-label"><!--{$lang.page.table.code}--></label>
              <div class="layui-input-inline">
                <input type="text" name="codes" value="<!--{$datainfo.codes}-->" lay-verify="codes"  placeholder="<!--{$lang.page.public.pinput}-->" autocomplete="off" class="layui-input" />
              </div>
            </div>

            <div class="layui-inline">
             <label class="layui-form-label"><!--{$lang.page.table.currency}--></label>
              <div class="layui-input-inline">
                <input type="text" name="abbr" value="<!--{$datainfo.abbr}-->" lay-verify="abbr" placeholder="<!--{$lang.page.public.pinput}-->" autocomplete="off" class="layui-input" />
              </div>
            </div>
          </div>

            <div class="layui-form-item">
                <div class="layui-inline">
                   <label class="layui-form-label"><!--{$lang.page.table.basecur}--></label>
                   <input type="radio" name="defualt" value="0" title="<!--{$lang.page.table.no}-->" <!--{if $datainfo.defualt eq 0}--> checked<!--{/if}-->  >&nbsp;&nbsp;<input type="radio" name="defualt" value="1" title="<!--{$lang.page.table.yes}-->" <!--{if $datainfo.defualt eq 1}--> checked<!--{/if}-->>
                </div>

                <div class="layui-inline">
                   <label class="layui-form-label"><!--{$lang.page.table.status}--></label>
                   <input type="radio" name="status" value="0" title="<!--{$lang.page.table.close}-->" <!--{if $datainfo.status eq 0}--> checked<!--{/if}-->  >&nbsp;&nbsp;<input type="radio" name="status" value="1" title="<!--{$lang.page.table.normal}-->" <!--{if $datainfo.status eq 1}--> checked<!--{/if}-->>
                </div>

                <div class="layui-inline">
                   <label class="layui-form-label"><!--{$lang.page.table.range}--></label>
                   <input type="radio" name="ranges" value="0" title="<!--{$lang.page.table.onsite}-->" <!--{if $datainfo.ranges eq 0}--> checked<!--{/if}-->  >&nbsp;&nbsp;<input type="radio" name="ranges" value="1" title="<!--{$lang.page.table.all}-->" <!--{if $datainfo.ranges eq 1}--> checked<!--{/if}-->>
                </div>
                <div class="layui-inline">
                   <label class="layui-form-label"><!--{$lang.page.table.type}--></label>
                   <input type="radio" name="type" value="1" title="<!--{$lang.page.table.entity}--><!--{$lang.page.table.account}-->" <!--{if $datainfo.type eq 1}--> checked<!--{/if}-->  >&nbsp;&nbsp;<input type="radio" name="type" value="2" title="<!--{$lang.page.table.fict}--><!--{$lang.page.table.account}-->" <!--{if $datainfo.type eq 2}--> checked<!--{/if}-->>
                </div>
            </div>
            <!--{if $authtype.authtype>1}-->
            <div class="layui-form-item">
              <label class="layui-form-label"><!--{$lang.page.public.inputcode}--></label>
                <div class="layui-inline">
                  <input type="text" name="code" lay-verify="code" placeholder="<!--{$lang.page.public.pinput}-->" autocomplete="off" class="layui-input">
                </div>
                <div class="layui-inline">
                  <button type="button" class="layui-btn" id="sendCode" ><!--{$lang.page.public.send}--></button>
                  <div class="layui-btn" id="timer" style="display: none"><!--{$lang.page.public.wait}--></div>
                </div>
                <div class="layui-inline">
                  <!--{$lang.page.public.showpwd1}-->
                </div>
            </div>
            <!--{/if}-->   
            <div class="layui-form-item layui-layout-admin">
              <div class="layui-footer" style="left: 0;">
                <button class="layui-btn" type="button" id="submit" lay-submit lay-filter="submit"><!--{$lang.page.public.submit}--></button>
                <button type="reset" class="layui-btn layui-btn-primary"><!--{$lang.page.public.reset}--></button>
                <button type="button" class="layui-btn layui-btn-primary" onClick="xadmin.close();" ><!--{$lang.page.table.back}--></button>
              </div>
            </div>

        </form>
      </div>
    </div>
<script src="/static/lay/layui/layui.js"></script>
<script type="text/javascript">
    layui.config({
     base: '/static/lay/' //静态资源所在路径
   }).extend({
     xadmin: 'lib/xadmin' //弹窗
   }).use(['jquery', 'layer','xadmin', 'form', 'element'], function(){
    var form = layui.form;
    form.render(null, 'component-form-group');
    var authtype = $('input[name="authtype"]').val(); 
     /* 自定义验证规则 */
    var rate = /^[0-9]+(\.[0-9]+)?$/;
    var codes = /^[a-zA-Z0-9]+$/u;
    form.verify({
      name: function(value){
        if(value.length < 1){
          return '<!--{$lang.page.table.name}--> <!--{$lang.page.public.nocontent}-->';
        }
      }
      ,rate: function(value){
        var flag = rate.test(value) || rate.test(value);
          if(!flag){
            return '<!--{$lang.page.public.pinput}--> <!--{$lang.page.table.right}--> <!--{$lang.page.table.rate}-->';
          }
      }
      ,codes: function(value){
        var flag = codes.test(value) || codes.test(value);
          if(!flag){
            return '<!--{$lang.page.public.pinput}--> <!--{$lang.page.table.right}--> <!--{$lang.page.table.code}-->';
          }
      }
      ,abbr: function(value){
        var flag = codes.test(value) || codes.test(value);
          if(!flag){
            return '<!--{$lang.page.public.pinput}--> <!--{$lang.page.table.right}--> <!--{$lang.page.table.currency}-->';
          }
      }
      ,code: function(value){
        if(value.length < 1 && authtype>1){
          return '<!--{$lang.page.public.inputcode}--><!--{$lang.page.public.nocontent}-->';
        }
      }

    });

    $('#sendCode').click(function(){
        $('#sendCode').attr("disabled",true);
        $('#sendCode').addClass('layui-btn-disabled');
        $.post('/admin/common/sendmail',{type:'authtype'},function(res){
                if(res.code == 200){
                  $('#sendCode').hide();
                  $('#timer').show();
                  timer(res.data.endtime);
                  layer.msg(res.msg);
                }else{
                  $('#sendCode').removeAttr("disabled");
                  $('#sendCode').removeClass('layui-btn-disabled');
                  layer.msg(res.msg);
                }
              })
    });

    form.on('submit(submit)', function (data) {
            $('#submit').attr("disabled",true);
            $('#submit').addClass('layui-btn-disabled');
            $.post('#',data.field,function(res){
                if(res.code == 200){
                    layer.msg(res.msg);
                      setTimeout(() => {
                          window.parent.location.reload();
                          xadmin.close();
                      }, 1000);
                }else{
                    $('#submit').removeAttr("disabled");
                    $('#submit').removeClass('layui-btn-disabled');
                    layer.msg(res.msg);
                }
            })
            return false; //阻止表单跳转。如果需要表单跳转，去掉这段即可。
    });

    function timer(time){
        var endtime =  time;
        if(endtime>0){
          let setInt=setInterval(() => {
              var countdownElement = document.getElementById("timer");
              var now = new Date().getTime(); // 当前时间
              var distance = Math.floor((endtime*1000 - now)/1000); // 距离结束日期还有多少时间
              if(distance<0){
                clearInterval(setInt); // 如果已经到达或超过了结束日期，清除定时器并隐藏倒计时元素
                countdownElement.style.display = "none";
                $('#sendCode').show();
                $('#sendCode').removeAttr("disabled");
                $('#sendCode').removeClass('layui-btn-disabled');
                return;
              }else{
                showtime = distance>0?distance:0;
                countdownElement.innerText = "" + showtime + "s"; // 更新倒计时内容
                return;
              }
          },1000)
        }else{
          countdownElement.style.display = "none";
          $('#sendCode').show();
      }
    }

  });
   

</script>
</body>
</html>

